package br.composer.methodologies;

import br.composer.handlers.handlers.DelayHandler;
import br.composer.handlers.requests.DelayHandlerRequest;
import br.composer.handlers.responses.HandlerResponse;
import br.composer.results.DelayResult;
import br.composer.rules.DelaySpatialCompositionRule;
import br.composer.util.TestOutput;

public class DelaySpatialCompositionMethodology extends SpatialCompositionMethodology{

	//requriments
	private DelayHandler delayHandler;
	
	//data objects
	private HandlerResponse delayHandlerResponses[];
	private DelayResult result;
	
	public DelaySpatialCompositionMethodology(TestOutput output,
			DelaySpatialCompositionRule rule, DelayHandler delayHandler) 
	{
		super(output, rule);
		this.delayHandler=delayHandler;
	}

	@Override
	public String getName() {
		return "Spatial Composition Methodology";
	}
	public HandlerResponse[] getDelayHandlerResponses() {
		return delayHandlerResponses;
	}
	public DelayResult getResult() {
		return result;
	}

	/*
	 * Partindo do principio que essa classe nao precisa ser generica, pois sera a classe
	 * a qual o usurio tera acesso direto. Logo, o metodo principal eh de escolha de cada
	 * metodologia (?) TODO rever 
	 * 
	 * TODO: Este metodo pode ser passado para um classe superior mais tarde
	 */
	public boolean applyMethodology(DelayHandlerRequest requests[]) {
		/**
		 * Each DelayHandlerRequest represents a sub-path, or the e2e measurement (src->dst)
		 */
		
		try {
			this.delayHandlerResponses = this.delayHandler.getResponse(requests);
			
			this.result = getRule().getResult(this.delayHandlerResponses[0]);
			
			return true;
		} catch (InterruptedException e) {
			e.printStackTrace();
			return false;
		}
	}

}
